/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.pz.net.master;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.DatagramChannel;

/**
 *
 * @author jannek
 */
public class StopMasterServer {
    public static void main(String[] args) throws IOException {
        File confirm = new File("confirmstop.txt");
        confirm.createNewFile();
        PrintWriter writer = new PrintWriter(confirm);
        writer.print("confirmstop");
        writer.close();
        int port = args.length > 0 ? Integer.parseInt(args[0]) : 13370;
        ByteBuffer data = ByteBuffer.allocate(4);
        data.clear();
        data.put("stop".getBytes()); // = 1937010544
        data.flip();
        DatagramChannel channel = DatagramChannel.open();
        channel.socket().bind(new InetSocketAddress(port - 1));
        channel.send(data, new InetSocketAddress("localhost", port));
    }

}
